{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "63671489",
   "metadata": {},
   "source": [
    "# 学习时间：2022-10-29\n",
    "# 记录者：张钰华\n",
    "# 学习内容：python目前所学的知识"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1646bf1",
   "metadata": {},
   "source": [
    "# 基本语法\n",
    " *  print()函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "db799ef7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello,python\n"
     ]
    }
   ],
   "source": [
    "# 练习(程序员与计算机的语言交流)\n",
    "# print(打印)，让计算机输出任何内容\n",
    "print(\"hello,python\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "986c9aa7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n"
     ]
    }
   ],
   "source": [
    "# num是变量，把100放进计算机名称为num的盒子当中，想要找到标签内容100时，就可以直接答应num这个盒子\n",
    "num = 100\n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d572cd4",
   "metadata": {},
   "source": [
    "* 数据类型(不同的数据类型有其不同的功能)\n",
    "* 字符串str(单，双，多引号；不可进行加减乘除运算，但可计算字符串长度)\n",
    "* 整数int(20/30...,可以进行加减乘除运算)\n",
    "* 浮点数float(带小数点的：183.6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b9d4fc77",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串(三引号可以换行输出,但单双不行）\n",
    "a = 'hello'# (在计算机里放了一个盒子，盒子里装着hello，给这个盒子贴上标签，标签名字为a，如果下次想找到内容为hello的时候，就可以直接打开a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "10a791aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1f4e66b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "boy\n",
      "girl  #(三引号可以换行输出)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "b = \"boy\"\n",
    "c = '''girl  #(三引号可以换行输出)\n",
    "'''\n",
    "print(b)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "77eee637",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n",
      "180.8\n"
     ]
    }
   ],
   "source": [
    "age = 20\n",
    "height = 180.8\n",
    "print(age)\n",
    "print(height)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "5a9bc4fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "90\n",
      "30\n",
      "1800\n",
      "0.5\n"
     ]
    }
   ],
   "source": [
    "# 整数类型可以运算\n",
    "f =30\n",
    "g =60\n",
    "print(f+g)\n",
    "print(g-f)\n",
    "print(f*g)\n",
    "print(f/g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "749efaff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "helloworld\n"
     ]
    }
   ],
   "source": [
    "# 字符串\n",
    "s1 = 'hello'\n",
    "s2 = 'world'\n",
    "print(s1+s2) #此时的加号是连接作用，把左边和有右边一起拼接，所以字符串是不能进行运算的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0b72c5a6",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for -: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [17]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ms1\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43ms2\u001b[49m)\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "print(s1-s2) # 报错了，则说明字符串类型不能实现他运算的功能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "15763393",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello! python\n"
     ]
    }
   ],
   "source": [
    "# 字符串数据类型独特的功能,而整数类型是没有的\n",
    "s = 'hello! world'\n",
    "s = s.replace('world','python') # replace()替换\n",
    "print(s)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2b95d433",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best girl\n"
     ]
    }
   ],
   "source": [
    "#例子\n",
    "s2 = 'best boy'\n",
    "s2 = s2.replace('boy','girl')\n",
    "print(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "062f7207",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "length = len(s2)\n",
    "print(length)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "260bc3da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n"
     ]
    }
   ],
   "source": [
    "length =len(s) # len()长度\n",
    "print(length)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2f954432",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "object of type 'int' has no len()",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m d \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m7\u001b[39m\n\u001b[1;32m----> 2\u001b[0m length \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43md\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28mprint\u001b[39m(length)\n",
      "\u001b[1;31mTypeError\u001b[0m: object of type 'int' has no len()"
     ]
    }
   ],
   "source": [
    "d = 7\n",
    "length = len(d)\n",
    "print(length)# 整数类型没有len（）功能"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c649148",
   "metadata": {},
   "source": [
    "# 输入函数input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c3a51692",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由计算机去提问，程序员去作答\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "edc90730",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 类型转换器\n",
    "age = int(age)\n",
    "print(type(age))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f442054",
   "metadata": {},
   "source": [
    "#  分支结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c9b9c43c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入取款金额：1000\n",
      "取款成功，余额为：2000\n"
     ]
    }
   ],
   "source": [
    "# 分支结构\n",
    "balance = 1000 # 银行卡余额\n",
    "money = input('请输入取款金额：')\n",
    "money = int(money) #修改类型转换器，将str转为int类型\n",
    "if money<= balance:   # 判断,取款金额与银行卡的余额进行比较\n",
    "    balance = balance+money # 计算新的余额\n",
    "    print('取款成功，余额为：'+ str(balance))\n",
    "else:\n",
    "    print(\"取款失败，余额不足，当前余额为:\"+ str(balance))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "7fd525fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入取款金额：2500\n",
      "取款失败，余额不足，当前余额为:1000\n"
     ]
    }
   ],
   "source": [
    "# 分支结构\n",
    "balance = 1000 # 银行卡余额\n",
    "money = input('请输入取款金额：')\n",
    "money = int(money) #修改类型转换器，将str转为int类型\n",
    "if money<= balance:   # 判断,取款金额与银行卡的余额进行比较\n",
    "    balance = balance+money # 计算新的余额\n",
    "    print('取款成功，余额为：'+ str(balance))\n",
    "else:\n",
    "    print(\"取款失败，余额不足，当前余额为:\"+ str(balance))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "384aed02",
   "metadata": {},
   "source": [
    "* 循环结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79f06049",
   "metadata": {},
   "source": [
    "# for ... in..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "b00ad585",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "# 循环结构\n",
    "for i in range(1,6):# 在range里的整数序列中得到1-5的整数，都要放到盒子i（或者其他任意命名的用来存放数据的盒子）里面\n",
    "    print(i) # range()从这个整数序列当中因此把里面的数展示出来的过程叫做遍历（左闭右开）只取5个值\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "46a7902d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p\n",
      "y\n",
      "t\n",
      "h\n",
      "o\n",
      "n\n"
     ]
    }
   ],
   "source": [
    "for h in 'python':\n",
    "    print(h) # for in 循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2cf3c3f7",
   "metadata": {},
   "source": [
    "# while"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "409a7d6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "# while循环---关键词，当...时候\n",
    "a = 3\n",
    "while a <=5: # 执行条件\n",
    "    print(a)\n",
    "    a = a+1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "991684ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "15\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "d = 10\n",
    "while d <=20:\n",
    "    print(d)\n",
    "    d=d+5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3d331d1",
   "metadata": {},
   "source": [
    "* 中断结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57055087",
   "metadata": {},
   "source": [
    "# break\n",
    "while True: # True无条件放行\n",
    "    answer = input('腿怎么样？能坚持吗？')\n",
    "    if answer == \"yes\": # （== 比较输出的答案）\n",
    "        print(\"加油，坚持就是胜利！\")\n",
    "        break\n",
    "else:\n",
    "        print('不能，快停下休息吧！请退出比赛')\n",
    "       \n",
    "       "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35cd9073",
   "metadata": {},
   "source": [
    "# while True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94d495ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# break\n",
    "while True: # True无条件放行\n",
    "    answer = input('腿怎么样？能坚持吗？')\n",
    "    if answer == \"yes\": # （== 比较输出的答案）\n",
    "        print(\"加油，坚持就是胜利！\")\n",
    "        break\n",
    "else:\n",
    "        print('不能，快停下休息吧！请退出比赛')\n",
    "        break # break只能用于while循环或者for循环中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88e6116f",
   "metadata": {},
   "source": [
    "# continue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "480a030d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "能跑吗？yes\n",
      "一共跑了 1 圈\n"
     ]
    }
   ],
   "source": [
    "circle = 0 # 代表能跑圈数\n",
    "for i in range(1,20):\n",
    "    answer = input('能跑吗？')\n",
    "    if answer!= 'yes':  # （！表示不能）\n",
    "        continue\n",
    "    circle= circle+1 # 变量，开跑圈数\n",
    "    print('一共跑了',circle,'圈') # 相当于 print（'一共跑了'+str（circle）+'圈'），用逗号代表加号\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "e730d33d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "能跑吗？n\n",
      "能跑吗？n\n",
      "能跑吗？n\n",
      "能跑吗？\n",
      "能跑吗？yes\n",
      "一共跑了 1 圈\n"
     ]
    }
   ],
   "source": [
    "circle = 0 # 代表能跑圈数\n",
    "for i in range(1,20):\n",
    "    answer = input('能跑吗？')\n",
    "    if answer!= 'yes':  # （！表示不能）\n",
    "        continue\n",
    "    circle= circle+1 # 变量，开跑圈数\n",
    "    print('一共跑了',circle,'圈') # 相当于 print（'一共跑了'+str（circle）+'圈'），用逗号代表加号\n",
    "    break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efa81ad2",
   "metadata": {},
   "source": [
    "#  数据结构--列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "919791c5",
   "metadata": {},
   "source": [
    "# 获取元素：list[index]\n",
    "# 新增元素: list.append(obj)\n",
    "# 修改元素：list[index]=obj\n",
    "# 删除元素：list.remove(obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "0cd6b558",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# list[40,42,42,43,44]\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "b364aa47",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 41, 42, 43, 44]\n"
     ]
    }
   ],
   "source": [
    "list=[40,41,42,43,44]\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "1ecf69fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40\n"
     ]
    }
   ],
   "source": [
    "# 想要获取列表中的数字40，就要找到它的所在位置，及索引值\n",
    "print(list[0]) # 获取元素：list[index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "6dd30907",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 53, 42, 43, 44, 100, 1000, 10000, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "# 添加元素\n",
    "list.append(100)# 一般加到尾部\n",
    "print(list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "cd4fdfd2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 53, 42, 43, 78, 100, 1000, 10000, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "# 修改元素---就要在列表中找到它的位置（索引值）\n",
    "list[4]=78\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "3596e0ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 42, 43, 78, 100, 1000, 10000, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "# 删除元素\n",
    "list.remove(53)\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "32e22fc3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 42, 43, 78, 100, 10000, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "list.remove(1000)\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "c33d7abd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 42, 43, 78, 10000, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "list.remove(100)\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "53fcd6fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 42, 43, 78, 100, 100]\n"
     ]
    }
   ],
   "source": [
    "list.remove(10000)\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "3c4b0769",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 42, 43, 78, 100]\n"
     ]
    }
   ],
   "source": [
    "list.remove(100)\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "456914fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40\n",
      "42\n",
      "43\n",
      "78\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "# 单列表中的数据过多，索引值复杂时，我们就要利用循环来执行我们元素获取、\n",
    "for i in range(0,len(list)): # 可以利用len()来计算我们的列表元素个数\n",
    "    print(list[i])     # 遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "5b06796f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40\n",
      "42\n",
      "43\n",
      "78\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "for item in list:\n",
    "    print(item)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "f23d86d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,len(list)):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f74eb1ef",
   "metadata": {},
   "source": [
    "# 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "bf634003",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[51, 52, 53, 54, 55, 56, 57, 58, 59, 60]\n"
     ]
    }
   ],
   "source": [
    "list1 = [50,51,52,53,54,55,56,57,58,59,60]  #如果我想去掉50，只想留着51-60的数\n",
    "list2= list1[1:] # 就要去从切片的索引值开始，切片数只保留切片右边的元素\n",
    "print(list2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "4fbf37fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[51, 52, 53, 54]\n"
     ]
    }
   ],
   "source": [
    "list1 = [50,51,52,53,54,55,56,57,58,59,60]  #如果我想去掉50，只想留着51-60的数\n",
    "list2= list1[1:5] # 切片元素左开右闭，不包括索引值为5的元素\n",
    "print(list2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "53708cbd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]\n"
     ]
    }
   ],
   "source": [
    "list1 = [50,51,52,53,54,55,56,57,58,59,60]  \n",
    "list2= list1[:] # 我也可以啥也不写，只留冒号，发现会把原列表数据复制一遍\n",
    "print(list2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88175634",
   "metadata": {},
   "source": [
    "# 切片是有双向索引的\n",
    "* 从左往右是正索引（0，1，2...）\n",
    "* 从右往左是逆索引(-1,-2,-3,...)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "bfcc3882",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[58, 59, 60]\n"
     ]
    }
   ],
   "source": [
    "# list1 = [50,51,52,53,54,55,56,57,58,59,60]  #此时60就为索引值-1\n",
    "list2= list1[-3:] # 就要去从切片的索引值开始，切片数只保留切片右边的元素\n",
    "print(list2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f4281f9",
   "metadata": {},
   "source": [
    "# 字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "56d1a135",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '43': 2} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "dict_size={'41':10,'42':8,'43':2} # 冒号左边为键key，右边为值value\n",
    "print(dict_size,type(dict_size))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cb9adadf",
   "metadata": {},
   "source": [
    "# 获取值元素：dict_size[key]\n",
    "# 新增元素：dict_size[key]=value\n",
    "# 修改元素：dict_size[key]=new_value\n",
    "# 删除元素：del dict_size[key]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "cff83329",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '43': 2}\n"
     ]
    }
   ],
   "source": [
    "dict_size={'41':10,'42':8,'43':2}\n",
    "print(dict_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "b9e6a277",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "# 想要找到字典中的具体元素(获取元素)\n",
    "print(dict_size['41'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "e026d71c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '43': 2, '48': 6}\n"
     ]
    }
   ],
   "source": [
    "# 新增元素\n",
    "dict_size['48']=6  # 等号来赋值\n",
    "print(dict_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "7b530bd2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '43': 2, '48': 12}\n"
     ]
    }
   ],
   "source": [
    "# 修改元素\n",
    "dict_size['48']=12\n",
    "print(dict_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "5df918ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '48': 12}\n"
     ]
    }
   ],
   "source": [
    "# 删除元素\n",
    "del dict_size['43']\n",
    "print(dict_size)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "335db989",
   "metadata": {},
   "source": [
    "* 字典没有索引值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "418c4dd8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41\n",
      "42\n",
      "48\n"
     ]
    }
   ],
   "source": [
    "for i in dict_size:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "f9057aa4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41 10\n",
      "42 8\n",
      "48 12\n"
     ]
    }
   ],
   "source": [
    "for i in dict_size:\n",
    "    print(i,dict_size[i])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6615209",
   "metadata": {},
   "source": [
    "# 数据结构---集合(离了婚的字典)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd8fb11c",
   "metadata": {},
   "source": [
    "* 集合：只有key（键），没有value（值）\n",
    "* 集合和字典都是以花括号去定义的\n",
    "* 集合是无序的，他只有新增元素和修改元素的特性\n",
    "* 集合是不能在其中获取元素的，因为集合没有索引值\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41fd7310",
   "metadata": {},
   "source": [
    "# 新增元素：dict_size.add(obj)\n",
    "# 删除元素：dict_size.remove(obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "8c6f3c63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'42', '41', '43'}\n"
     ]
    }
   ],
   "source": [
    "# 基本操作\n",
    "s={'41','42','43'} # 说明首位的数字不一定就在第一个，也证明出集合是无序的特征\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "7b51e0b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'42', '45', '41', '43'}\n"
     ]
    }
   ],
   "source": [
    "# 新增元素\n",
    "s.add('45') #新增的元素不一定就在尾部增加，与字典区分，集合元素是不固定的排列的\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "07cf0ff7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'42', '45', '41'}\n"
     ]
    }
   ],
   "source": [
    "# 删除元素\n",
    "s.remove('43')\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "c8c00859",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42\n",
      "45\n",
      "41\n"
     ]
    }
   ],
   "source": [
    "# 可以遍历，在集合当中逐一列取数据\n",
    "for i in s:\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2b94cd3",
   "metadata": {},
   "source": [
    "# 数据结构---元组\n",
    "* 元组特性：以小括号去定义的（）\n",
    "# 元组具有不可变性，是不可变的序列\n",
    "*（不能新增，不能修改，不能删除，只能查看）\n",
    "* 可以获取元素，与列表相似"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "f3cb1735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('41', '41', '43', '42') <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "tuple_size=('41','41','43','42')\n",
    "print(tuple_size,type(tuple_size))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "e1cea179",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['40', '42', '41', '42', '42', '43'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "list = ['40','42','41','42','42','43']\n",
    "print(list,type(list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "452d1277",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'41': 10, '42': 8, '43': 2} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "dict_size = {'41':10,'42':8,'43':2,'41':10,'42':8}\n",
    "print(dict_size,type(dict_size))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "373b1e11",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'42', '41', '43'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "s={'41','42','43','42','41','43'}\n",
    "print(s,type(s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "120ec675",
   "metadata": {},
   "source": [
    "# 列表和元组可以存放重复数据，但集合和字典不允许存放重复数据,重复的数据不能被打印出来\n",
    "* 以上述为例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "8e11b37e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41\n",
      "41\n",
      "43\n",
      "42\n"
     ]
    }
   ],
   "source": [
    "# 元组进行获取元素，遍历\n",
    "for i in tuple_size:   # 将元组的每个数据依次进行打印输出\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b97aed0b",
   "metadata": {},
   "source": [
    "# 数据结构总结\n",
    "* 1.数据结构列表（list）,可变序列，有序性，可以重复列表数据，定义符号：[ ]\n",
    "* 2.元组(tuple),不可变，有序性，可重复，定义符号：( )\n",
    "* 3.字典（dict）,可变（key不可重复，value可重复），无序性，定义符号：{key:value}\n",
    "* 4.集合(set),可变，不可重复数据，无序性，定义符号：{ }\n",
    "# 不可变性（不可增删改元素，但可查看获取）\n",
    "# 有序性（首位位置固定，不改变）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64f493a9",
   "metadata": {},
   "source": [
    "# 模块\n",
    "* 导入模块import"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fafd924",
   "metadata": {},
   "source": [
    "# 变量:保存和表示数据\n",
    "world='北京欢迎你'\n",
    "print(world)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "08ac7ec4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "8 <class 'int'>\n",
      "我爱你 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 变量名=value，type()可以查看数据类型，变量名需要有效的标识符\n",
    "lucky_num=8 # 创建一个整型变量lucky_num,并为其赋值为8\n",
    "print(lucky_num)\n",
    "print(lucky_num,type(lucky_num))\n",
    "lucky_num = '我爱你'\n",
    "print(lucky_num,type(lucky_num))  # 变量的值可以修改，不同的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "3da7c6e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1024 1024\n",
      "2177190455472\n",
      "2177190455472\n"
     ]
    }
   ],
   "source": [
    "no = number =1024\n",
    "print(no,number)  #允许多个变量指向同一个值\n",
    "print(id(no))\n",
    "print(id(number)) # 用id内置函数查看地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "65011d69",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "地址:广州市从化区温泉镇温大道\n",
      "收件人：张小花\n",
      "手机号：13700000000\n"
     ]
    }
   ],
   "source": [
    "# 多行字符串\n",
    "info = '''地址:广州市从化区温泉镇温大道\n",
    "收件人：张小花\n",
    "手机号：13700000000'''\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "b4830b21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "北京\n",
      "欢迎你\n"
     ]
    }
   ],
   "source": [
    "print('北京\\n欢迎你')  # \\n为换行符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "558f4b03",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "十\n",
      "一\n",
      "月\n",
      "我\n",
      "我\n",
      "来\n",
      "了\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('十\\n一\\n月\\n我\\n我\\n来\\n了\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "ab2c91fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h h\n"
     ]
    }
   ],
   "source": [
    "# 字符串索引，字符串或字符串变[序号]，正向从左到右，由0开始，方向由右到左，-1开始\n",
    "s='helloworld'\n",
    "print(s[0],s[-10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "7bc90fbb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "world\n"
     ]
    }
   ],
   "source": [
    "# 字符串切片，字符串或字符串变量[n:m]\n",
    "# 切片获取字符串中从n到m（不包括m）的子字符串\n",
    "s='helloworld'\n",
    "print(s[5:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "66ea70cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "world\n"
     ]
    }
   ],
   "source": [
    "s='helloworld'\n",
    "print(s[-5:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "id": "fc7ab70c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你爱我吗？爱\n",
      "present\n"
     ]
    }
   ],
   "source": [
    "#input()\n",
    "present = input('你爱我吗？')\n",
    "print('present')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "17d482e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个加数10\n",
      "请输入另一个加数20\n",
      "1020\n",
      "10 <class 'str'>\n",
      "20 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "#要求从键盘区去录入两个整数数 ，去计算两个整数的和\n",
    "a = input('请输入一个加数')\n",
    "b = input ('请输入另一个加数')\n",
    "print(a+b) # 此时加号起来连接作用，并没有进行想加运算\n",
    "print(a,type(a)) # input()使用的是str类型\n",
    "print(b,type(b))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "id": "145508b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个加数10\n",
      "请输入另一个加数20\n",
      "30\n",
      "10 <class 'int'>\n",
      "20 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 类型转换\n",
    "a = input('请输入一个加数')\n",
    "a=int(a)\n",
    "b = input ('请输入另一个加数')\n",
    "b=int(b)\n",
    "print(a+b)\n",
    "print(a,type(a))\n",
    "print(b,type(b))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "0aacf478",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个加数10\n",
      "请输入另一个加数20\n",
      "30\n",
      "10 <class 'int'>\n",
      "20 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 类型转换(方法二)\n",
    "a =int(input('请输入一个加数'))\n",
    "\n",
    "b = int(input ('请输入另一个加数'))\n",
    "\n",
    "print(a+b)\n",
    "print(a,type(a))\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "d000d096",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "# 赋值运算符，从右往左\n",
    "a=3+4\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "86134402",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20 2177069771664 <class 'int'>\n",
      "20 2177069771664 <class 'int'>\n",
      "20 2177069771664 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a=b=c=20 # 将20赋给了c，b，a(链式赋值)\n",
    "print(a,id(a),type(a))\n",
    "print(b,id(b),type(b))\n",
    "print(c,id(c),type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39a92645",
   "metadata": {},
   "source": [
    "# 程序的组织结构\n",
    "* 顺序结构\n",
    "* 选择结构（if语句）\n",
    "* 循环结构（while语句/for...in语句）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "97f273d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------程序开始------\n",
      "1.把冰箱门打开\n",
      "2.把大象放进去\n",
      "3.把冰箱门关上\n",
      "-------程序结束-----\n"
     ]
    }
   ],
   "source": [
    "# 顺序结构（由上到下）\n",
    "# 把大象放进冰箱需要几步\n",
    "print('------程序开始------')\n",
    "print('1.把冰箱门打开')\n",
    "print('2.把大象放进去')\n",
    "print('3.把冰箱门关上')\n",
    "print('-------程序结束-----')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "id": "bd95f595",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 测试对象的布尔值\n",
    "print(bool(False))\n",
    "print(bool(0))\n",
    "print(bool(None))\n",
    "print(bool('')) # 长度为0的字符串/集合\n",
    "print(bool([])) # 空列表\n",
    "print(bool())# 空元组/字典\n",
    "print(bool({}))\n",
    "print(bool(set()))\n",
    "print(bool(dict()))\n",
    "print(bool(tuple()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b179c43",
   "metadata": {},
   "source": [
    "# 单分支结构---选择结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "9cd89367",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入取款金额500\n",
      "取款成功，余额为: 500\n"
     ]
    }
   ],
   "source": [
    "# 明确让计算机在什么条件下在做什么，使用程序来做什么\n",
    "# 单：如果...就...\n",
    "money = 1000 # 余额\n",
    "a=int(input('请输入取款金额')) # 取款金额\n",
    "# 判断取款金额是否充足\n",
    "if a >= money:  # 条件表达式\n",
    "    print('取款失败，请充值')    # 判断结果false/true，只有执行条件为true，才会执行下一行代码\n",
    "else:\n",
    "    money= money-a\n",
    "    print(\"取款成功，余额为:\",money)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "id": "2dade6e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入取款金额1200\n",
      "取款失败，请充值\n"
     ]
    }
   ],
   "source": [
    "# 明确让计算机在什么条件下在做什么，使用程序来做什么\n",
    "# 单：如果...就...\n",
    "money = 1000 # 余额\n",
    "a=int(input('请输入取款金额')) # 取款金额\n",
    "# 判断取款金额是否充足\n",
    "if a >= money:  # 条件表达式\n",
    "    print('取款失败，请充值')   \n",
    "else:\n",
    "    money= money-a  # \"余额还剩多少\"\n",
    "    print(\"取款成功，余额为:\",money)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0926d2b",
   "metadata": {},
   "source": [
    "* 双分支结构（如果...不满足...就...）\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "id": "3d603c1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数9\n",
      "9 是奇数\n"
     ]
    }
   ],
   "source": [
    "# if...else（二选一执行）\n",
    "# 从键盘录入一个整数，编写程序，让计算机判断是奇数还是一个偶数\n",
    "a= int(input('请输入一个整数'))\n",
    "# 条件判断奇数还是偶数\n",
    "if a%2==0:    #\"%\"---取余的意思\n",
    "    print(a,'是偶数')\n",
    "else:\n",
    "    print(a,'是奇数')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "id": "3c8a8e0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数10\n",
      "10 是偶数\n"
     ]
    }
   ],
   "source": [
    "# if...else（二选一执行）\n",
    "# 从键盘录入一个整数，编写程序，让计算机判断是奇数还是一个偶数\n",
    "a= int(input('请输入一个整数'))\n",
    "# 条件判断奇数还是偶数\n",
    "if a%2==0:\n",
    "    print(a,'是偶数')\n",
    "else:\n",
    "    print(a,'是奇数')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3a937f2",
   "metadata": {},
   "source": [
    "* 多分支结构（连续区间段）\n",
    "* 多选一执行\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "id": "e2ef6951",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型98\n",
      "A\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "id": "540d08a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型85\n",
      "B\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "0dfa2f79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型75\n",
      "C\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "0bcce7e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型65\n",
      "D\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "4a468fc6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型55\n",
      "E\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "id": "8e52c0af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入成绩类型120\n",
      "对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！\n"
     ]
    }
   ],
   "source": [
    "# 要求从键盘中录入一个整数成绩，然后判断成绩的范围\n",
    "# 90-100：A ;80-89:B;70-79:C;60-69:D;0-59 E; 小于0大于100为非法数据，不是成绩的有效区间\n",
    "score=int(input('请输入成绩类型'))\n",
    "if score>=90 and score<=100:    # 如果第一个条件表达句为false，则会进行下一行的条件表达句，如果是true，就不用再进行下一行的连续判断。\n",
    "    print('A')\n",
    "elif score>=80 and score<=89:\n",
    "    print('B')\n",
    "elif score>=70 and score<=79:\n",
    "    print('C')\n",
    "elif score>=60 and score <=69:\n",
    "    print(\"D\")\n",
    "elif score>=0 and score<=59:\n",
    "    print('E')\n",
    "else:\n",
    "    print('对不起，您的成绩有误，不在有效区间范围，请输入有效成绩！')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84c6eeed",
   "metadata": {},
   "source": [
    "# 嵌套if"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "1a35ea30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您是会员吗？yes\n",
      "请输入您的购物金额:200\n",
      "付款金额为: 160.0\n"
     ]
    }
   ],
   "source": [
    "# 会员>=200,8折；>=100，9折；不打折\n",
    "# 非会员 >=200，9.5折；不打折\n",
    "answer= input('您是会员吗？')# 首先判断是否是会员身份\n",
    "money = float(input('请输入您的购物金额:'))\n",
    "if answer=='yes':  # 会员\n",
    "    if money>=200:\n",
    "        print('付款金额为:',money*0.8)\n",
    "elif money>=100: \n",
    "        print('付款金额为:',money*0.9)\n",
    "else:\n",
    "    print('不打折') \n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "bf4c46d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您是会员吗？yes\n",
      "请输入您的购物金额:120\n",
      "打九折,付款金额为: 108.0\n"
     ]
    }
   ],
   "source": [
    "# 会员>=200,8折；>=100，9折；不打折\n",
    "# 非会员 >=200，9.5折；不打折\n",
    "answer= input('您是会员吗？')# 首先判断是否是会员身份\n",
    "money = float(input('请输入您的购物金额:'))\n",
    "if answer=='yes':  # 会员\n",
    "    if money>=200:\n",
    "        print('打八折,付款金额为:',money*0.8)\n",
    "    elif money>=100: \n",
    "        print('打九折,付款金额为:',money*0.9)\n",
    "    else:\n",
    "        print('不打折,付款金额为:',money)\n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "cc8beb5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您是会员吗？yes\n",
      "请输入您的购物金额:50\n",
      "不打折,付款金额为: 50.0\n"
     ]
    }
   ],
   "source": [
    "# 会员>=200,8折；>=100，9折；不打折\n",
    "# 非会员 >=200，9.5折；不打折\n",
    "answer= input('您是会员吗？')# 首先判断是否是会员身份\n",
    "money = float(input('请输入您的购物金额:'))\n",
    "if answer=='yes':  # 会员\n",
    "    if money>=200:\n",
    "        print('打八折,付款金额为:',money*0.8)\n",
    "    elif money>=100: \n",
    "        print('打九折,付款金额为:',money*0.9)\n",
    "    else:\n",
    "        print('不打折,付款金额为:',money)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "ac54b8fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您是会员吗？no\n",
      "请输入您的购物金额:500\n",
      "打九五折,付款金额为: 475.0\n"
     ]
    }
   ],
   "source": [
    "# 会员>=200,8折；>=100，9折；不打折\n",
    "# 非会员 >=200，9.5折；不打折\n",
    "answer= input('您是会员吗？')# 首先判断是否是会员身份\n",
    "money = float(input('请输入您的购物金额:'))\n",
    "if answer=='no':  # 非会员\n",
    "    if money>=200:\n",
    "        print('打九五折,付款金额为:',money*0.95)\n",
    "    else:\n",
    "        print('不打折,付款金额为:',money)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "0fe4282a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您是会员吗？no\n",
      "请输入您的购物金额:100\n",
      "不打折,付款金额为: 100.0\n"
     ]
    }
   ],
   "source": [
    "# 会员>=200,8折；>=100，9折；不打折\n",
    "# 非会员 >=200，9.5折；不打折\n",
    "answer= input('您是会员吗？')# 首先判断是否是会员身份\n",
    "money = float(input('请输入您的购物金额:'))\n",
    "if answer=='no':  # 非会员\n",
    "    if money>=200:\n",
    "        print('打九五折,付款金额为:',money*0.95)\n",
    "    else:\n",
    "        print('不打折,付款金额为:',money)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "id": "82e9c0b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数100\n",
      "请输入另外一个整数200\n",
      "200 s小于q\n"
     ]
    }
   ],
   "source": [
    "# 录入两个整数，比较这两个整数的大小\n",
    "s=int(input('请输入一个整数'))\n",
    "q=int(input('请输入另外一个整数'))\n",
    "if s>q:\n",
    "    print(s,'s大于q')\n",
    "else:\n",
    "    print(q,'s小于q')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "id": "5640927d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数1000\n",
      "请输入另外一个整数800\n",
      "1000 s大于q\n"
     ]
    }
   ],
   "source": [
    "# 录入两个整数，比较这两个整数的大小\n",
    "s=int(input('请输入一个整数'))\n",
    "q=int(input('请输入另外一个整数'))\n",
    "if s>q:\n",
    "    print(s,'s大于q')\n",
    "else:\n",
    "    print(q,'s小于q')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83660f58",
   "metadata": {},
   "source": [
    "# range()函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "id": "2cd37606",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "range(0, 10)\n"
     ]
    }
   ],
   "source": [
    "a=range(10) # 默认由0开始\n",
    "print(a)\n",
    "b=range(1,10)# start：1，stop：10，不包含10  #(1-9)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "id": "fd23cae7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 判断指定的整数，在这个序列中是否存在in，not in\n",
    "c=range(1,10)\n",
    "print(10 in c) #  False，判断10是否在c这个序列当中\n",
    "print(6 in c)\n",
    "print(12 not in c)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "id": "9528a06e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 101 1\n"
     ]
    }
   ],
   "source": [
    "# 三个数值\n",
    "# range(1,10,2) # 分别表示start /stop/ step\n",
    "#例子\n",
    "print(1,101,1) #表示1-100，步长为1的1序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "id": "c03afc72",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af2e77b8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
